package mysql

import (
	"api/global"
	"api/model"
)

func AddCaptcha(captcha *model.Captcha) (string, error) {
	err := global.DBHandle.Create(captcha).Error
	if err != nil {
		return "", err
	}
	return captcha.ID, nil
}

func GetCaptcha(id string) (captcha *model.Captcha, err error) {
	err = global.DBHandle.Where("id = ?", id).First(&captcha).Error
	if err != nil {
		return nil, err
	}

	return captcha, nil
}

func DeleteCaptcha(id string) (err error) {
	err = global.DBHandle.Where("id = ?", id).Delete(&model.Captcha{}).Error
	if err != nil {
		return
	}
	return
}
